﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.IO;

namespace SCFHS.Shared
{
    public partial class GetImages : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Count > 0)
            {
                XDocument doc = XDocument.Load(Server.MapPath("Storage.xml"));
                if (doc != null)
                {
                    XElement elemnt = doc.Root.Elements().Where(ele => ele.Attribute("ID").Value == Request.QueryString["imgID"]).First();
                    string imgUrl = elemnt.Element("img").Value;

                    System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath((string)imgUrl));
                    MemoryStream mems = new MemoryStream();
                    img.Save(mems, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Response.BinaryWrite(mems.ToArray());
                }
            }
        }
    }
}